<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">


 <title>SmallSharpTools.Packer - Trac</title><link rel="start" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki"><link rel="search" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/search"><link rel="help" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki/TracGuide"><link rel="stylesheet" href="SmallSharpTools.Packer_files/trac.css" type="text/css"><link rel="stylesheet" href="SmallSharpTools.Packer_files/wiki.css" type="text/css"><link rel="icon" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/chrome/common/trac.ico" type="image/x-icon"><link rel="shortcut icon" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/chrome/common/trac.ico" type="image/x-icon"><link rel="alternate" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki/WikiStart?format=txt" title="Plain Text" type="text/x-trac-wiki"><style type="text/css">
</style>
 <script type="text/javascript" src="SmallSharpTools.Packer_files/trac.js"></script>
</head><body>


<div id="banner">

<div id="header"><a id="logo" href="http://example.org/"><img src="SmallSharpTools.Packer_files/trac_banner.png" alt=""></a><hr></div>

<form id="search" action="/trac/SmallSharpTools.Packer/search" method="get">
 <div>
  <label for="proj-search">Search:</label>
  <input id="proj-search" name="q" size="10" accesskey="f" type="text">
  <input value="Search" type="submit">
  <input name="wiki" value="on" type="hidden">
  <input name="changeset" value="on" type="hidden">
  <input name="ticket" value="on" type="hidden">
 </div>
</form>



<div id="metanav" class="nav"><ul><li class="first"><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/login">Login</a></li><li><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/settings">Settings</a></li><li><a accesskey="6" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki/TracGuide">Help/Guide</a></li><li class="last"><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/about">About Trac</a></li></ul></div>
</div>

<div id="mainnav" class="nav"><ul><li class="active first"><a accesskey="1" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki">Wiki</a></li><li><a accesskey="2" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/timeline">Timeline</a></li><li><a accesskey="3" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/roadmap">Roadmap</a></li><li><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/browser">Browse Source</a></li><li><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/report">View Tickets</a></li><li class="last"><a accesskey="4" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/search">Search</a></li></ul></div>
<div id="main">




<div id="ctxtnav" class="nav">
 <h2>Wiki Navigation</h2>
 <ul>
   <li><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki">Start Page</a></li>
   <li><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki/TitleIndex">Index by Title</a></li>
   <li><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki/RecentChanges">Index by Date</a></li>
   <li class="last"><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki/WikiStart?action=diff&amp;version=43">Last Change</a></li>
 </ul>
 <hr>
</div>

<div id="content" class="wiki">

 
  
  
   
   <div class="wikipage">
    <div id="searchable"><h1 id="Packerfor.NET">Packer for .NET
</h1>
<ul><li><a class="ext-link" href="http://svn.offwhite.net/svn/SmallSharpTools.Packer/trunk/README.txt"><span class="icon">README</span></a>
</li><li><a class="ext-link" href="http://www.smallsharptools.com/Downloads/SmallSharpTools.Packer/"><span class="icon">Download</span></a>
</li><li><a class="ext-link" href="http://www.smallsharptools.com/"><span class="icon">SmallSharpTools.com</span></a>
</li></ul><h2 id="Recognition">Recognition
</h2>
<p>
It was great to see that Scott Hanselman has placed Packer for .NET on his annual list.
</p>
<ul><li><a class="ext-link" href="http://www.hanselman.com/blog/ScottHanselmans2007UltimateDeveloperAndPowerUsersToolListForWindows.aspx"><span class="icon">Scott Hanselman's 2007 Ultimate Developer and Power Users Tool List for Windows</span></a>
</li></ul><h2 id="IncludedPackages">Included Packages
</h2>
<ul><li><a class="ext-link" href="http://dean.edwards.name/packer/"><span class="icon">Packer, A JavaScript Compressor</span></a>
</li><li><a class="ext-link" href="http://www.crockford.com/javascript/jsmin.html"><span class="icon">JSMin, The JavaScript Minifier</span></a>
</li><li><a class="ext-link" href="http://code.google.com/p/cssmin/"><span class="icon">CSSMin, The CSS Minifier</span></a>
</li></ul><h2 id="Whatisit">What is it?
</h2>
<p>
Packer for .NET is a tool derived from Packer which reduces the size of
JavaScript files. The changes made with Packer for .NET include a
command-line version which uses the same classes included with the
official Packer download. This command-line tool can take multiple
filenames to compress them all together into a single packed output.
The existing WinForms version limited the amount of text allowed in the
input window and did not take filenames as input. This re-packaged
version makes it easier to automate build and deployment tasks.
</p>
<p>Packer for .NET also supports a mode to use JSMin. It uses a
different process which simply strips comments and whitespace from the
source scripts. In the cases where the Packer mode is unable to
transform a script it may be possible to use JSMin instead.
</p>
<h2 id="PackerversusJSMin">Packer versus JSMin?
</h2>
<p>The merits of Packer and JSMin can be measured in file size and time
to interpret. While Packer can created a much smaller output file it
can be more problematic with packing JavaScript that does not conform
to a strict syntax. JSMin still prefers that you use semicolons at the
end of each line, but it tends to have fewer problems with parsing and
minifying the output. Beyond file size, the time it takes interpret a
packed/minified JavaScript file should also be a consideration. <a class="ext-link" href="http://ejohn.org/blog/John"><span class="icon">Resig</span></a>
ran a series of tests with Packer and JSMin and determined that JSMin
appears to give you the best of compression and time for interpretation
while Packer does have a performance hit when it has to be unpacked and
interpreted.
</p>
<p>One tool to assist with ensuring JavaScript works well with Packer
and JSMin is JavaScript Lint which integrates well with Visual Studio.
See the links below.
</p>
<ul><li><a class="ext-link" href="http://ejohn.org/blog/library-loading-speed/"><span class="icon">JavaScript Library Loading Speed</span></a>
</li><li><a class="ext-link" href="http://www.javascriptlint.com/"><span class="icon">JavaScript Lint</span></a>
</li></ul><h2 id="CSSMin">CSSMin
</h2>
<p>You can now shrink your CSS Files with the new CSSMin mode. You
simply select this new mode and your comments will be stripped and
various optimizations will be run on your stylesheets. <a class="ext-link" href="http://brennan.offwhite.net/blog/2008/11/23/packer-for-net-401-released/"><span class="icon">More Info</span></a>
</p>
<h2 id="Combine">Combine
</h2>
<p>
One new mode added in version 4.1 is Combine which simply appends each
of the specified files into a single file. This can be useful if you
wish to take all of your stylesheets and combine them into one for use
in a Production environment after using them as separate files which
are easier to maintain with multiple developers during development.
</p>
<h2 id="Command-lineUsage">Command-line Usage
</h2>
<pre class="wiki">Usage: Packer [-?|-h] [-o &lt;filename&gt;] [-m &lt;packer | jsmin | cssmin | combine&gt;] &lt;file1&gt; &lt;file2&gt; ...

 Options:
  -h or -?              Help
  -o &lt;filename&gt;         Output Filename
  -m &lt;packer | jsmin&gt;   Mode
</pre><h2 id="MSBuildUsage">MSBuild Usage
</h2>
<ul><li><a class="ext-link" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/browser/trunk/sample.proj"><span class="icon">sample.proj</span></a>
</li><li><a class="ext-link" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/browser/trunk/MSBuild.Packer.Targets"><span class="icon">MSBuild.Packer.Targets</span></a>
</li><li><a class="ext-link" href="http://brennan.offwhite.net/blog/2006/11/30/7-steps-to-msbuild/"><span class="icon">7 Steps to MSBuild</span></a>
</li></ul><pre class="wiki">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;

  &lt;Import Project="$(MSBuildExtensionsPath)\SmallSharpTools.Packer\MSBuild.Packer.Targets" /&gt;

  &lt;PropertyGroup&gt;
    &lt;Configuration Condition=" '$(Configuration)' == '' "&gt;Debug&lt;/Configuration&gt;
    &lt;Environment Condition=" '$(Environment)' == '' "&gt;Production&lt;/Environment&gt;

    &lt;PackerOutputFileName&gt;packer.msbuild.js&lt;/PackerOutputFileName&gt;
    &lt;JSMinOutputFileName&gt;jsmin.msbuild.js&lt;/JSMinOutputFileName&gt;
    &lt;CSSMinOutputFileName&gt;cssmin.msbuild.css&lt;/CSSMinOutputFileName&gt;

    &lt;WebConfigPath&gt;$(SampleFilesDir)\Web.config&lt;/WebConfigPath&gt;
    &lt;WebConfigOutputPath&gt;$(SampleFilesDir)\Output\Web.config&lt;/WebConfigOutputPath&gt;

    &lt;!-- Development --&gt;
    &lt;AppSettings Condition=" '$(Environment)' == 'Development' "&gt;
      Environment = Development;
    &lt;/AppSettings&gt;

    &lt;!-- Staging --&gt;
    &lt;AppSettings Condition=" '$(Environment)' == 'Staging' "&gt;
      Environment = Staging;
      SSL.Enabled = false;
    &lt;/AppSettings&gt;

    &lt;!-- Production --&gt;
    &lt;AppSettings Condition=" '$(Environment)' == 'Production' "&gt;
      Environment = Production;
      SSL.Enabled = true;
      SSL.Host = https://www.acme.com
    &lt;/AppSettings&gt;

  &lt;/PropertyGroup&gt;
  &lt;ItemGroup&gt;
    &lt;JavaScriptInputFiles Include="scripts\*.js" /&gt;
    &lt;CSSInputFiles Include="scripts\*.css" /&gt;
  &lt;/ItemGroup&gt;
  &lt;Target Name="Build"&gt;
    &lt;Packer OutputFileName="$(PackerOutputFileName)" Mode="Packer" InputFiles="@(JavaScriptInputFiles )" Verbose="false" /&gt;
    &lt;Packer OutputFileName="$(JSMinOutputFileName)" Mode="JSMin" InputFiles="@(JavaScriptInputFiles )" Verbose="false" /&gt;
    &lt;Packer OutputFileName="$(CSSMinOutputFileName)" Mode="CSSMin" InputFiles="@(CSSInputFiles )" Verbose="false" /&gt;

    &lt;!-- Development --&gt;
    &lt;UpdateWebConfig Condition=" '$(Environment)' == 'Development' "
        WebConfigPath="$(WebConfigPath)"
        OutputPath="$(WebConfigOutputPath)"
        ConnectionStringConfigSource="$(ConnectionStringConfigSource)"
        AppSettings="$(AppSettings)"
        Debug="true"
        CustomErrorsMode="Off"
        MailHost="localhost"/&gt;

    &lt;!-- Staging --&gt;
    &lt;UpdateWebConfig Condition=" '$(Environment)' == 'Staging' "
        WebConfigPath="$(WebConfigPath)"
        OutputPath="$(WebConfigOutputPath)"
        ConnectionStringConfigSource="Configurations\\connectionStrings-staging.config"
        AppSettings="$(AppSettings)"
        Debug="false"
        CustomErrorsMode="Remote"
        MailHost="staging.acme.com"/&gt;

    &lt;!-- Production --&gt;
    &lt;UpdateWebConfig Condition=" '$(Environment)' == 'Production' "
        WebConfigPath="$(WebConfigPath)"
        OutputPath="$(WebConfigOutputPath)"
        ConnectionStringConfigSource="Configurations\\connectionStrings-production.config"
        AppSettings="$(AppSettings)"
        Debug="false"
        CustomErrorsMode="On"
        MailHost="mail.acme.com"/&gt;

  &lt;/Target&gt;
&lt;/Project&gt;
</pre><h2 id="UpdateWebConfig">UpdateWebConfig
</h2>
<p>
The UpdateWebConfig task is new in version 4.1. It is a simpler option than the XmlUpdate task which is a part of the <a class="ext-link" href="http://msbuildtasks.tigris.org/"><span class="icon">MSBuild Community Tasks</span></a>.
Instead of providing an XPath value to map out replacements, this
UpdateWebConfig task makes it easy to replace commonly updated values
during deployment, like the connection string !configSource, customer
errors mode, debug mode, mail host and application settings. Not having
to set the XPath for XmlUpdate show make your MSBuild script easier to
read and maintain. </p>
<p>
The UpdateWebConfig task is designed to run after a build has completed
and is being prepared for deployment. The assembly is very small and
can easily be included with your deployment files to carry out the
UpdateWebConfig task at various points in your deployment. It is also
not necessary to install Packer for .NET to use the UpdateWebConfig or
even the Packer task. Refer to the test script for an example of the
UsingTask directive.
</p>
<p>For the UpdateWebConfig task the WebConfigPath must point to a valid
Web.config file used with ASP.NET. And optionally the OutputPath can be
set. If it is not set the output will be written to the WebConfigPath.
</p>
<p>
Also see <a class="ext-link" href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/browser/trunk/test.proj"><span class="icon">test.proj</span></a> for a working example.
</p>
<h2 id="MoreInformation">More Information
</h2>
<ul><li><a class="ext-link" href="http://www.andrewdupont.net/2007/02/26/packing-prototype/"><span class="icon">Packing Prototype</span></a>
</li><li><a class="ext-link" href="http://www.stevekallestad.com/wiki/Compressed_Javascript_Libraries"><span class="icon">Compressed JavaScript Libraries</span></a>
</li></ul><h2 id="Credits">Credits
</h2>
<p>
Packer was originally ported to C# by Jessie Hansen. (See <a class="ext-link" href="http://dean.edwards.name/weblog/2005/04/packer-goes-net/"><span class="icon">Packer Goes .NET</span></a>) 
</p>
<p>
JSMin was created by Douglas Crockford. (<a class="ext-link" href="http://www.crockford.com/"><span class="icon">www.crockford.com</span></a>)
</p>
<p>
CSSMin was originally written in Java by Isaac Schlueter. Then it was ported to C# by <a class="ext-link" href="http://www.dimebrain.com/2008/03/a-better-css-mi.html"><span class="icon">Daniel Crenna</span></a>.
New css tests and regexes were added by <a class="ext-link" href="http://regexadvice.com/blogs/mash/archive/2008/04/27/Update-to-CSS-Minification.aspx"><span class="icon">Michael Ash</span></a>. Finally
are additional cleaned up, commenting and refactoring by Chris Lienert it was incorporated into this project.
</p>
</div>
   </div>
   
  
  <script type="text/javascript">
   addHeadingLinks(document.getElementById("searchable"), "Link to this section");
  </script>
 
 
</div>

<script type="text/javascript">searchHighlight()</script>
<div id="altlinks"><h3>Download in other formats:</h3><ul><li class="first last"><a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki/WikiStart?format=txt">Plain Text</a></li></ul></div>

</div>

<div id="footer">
 <hr>
 <a id="tracpowered" href="http://trac.edgewall.org/"><img src="SmallSharpTools.Packer_files/trac_logo_mini.png" alt="Trac Powered" height="30" width="107"></a>
 <p class="left">
  Powered by <a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/about"><strong>Trac 0.10.2</strong></a><br>
  By <a href="http://www.edgewall.org/">Edgewall Software</a>.
 </p>
 <p class="right">
  Visit the Trac open source project at<br><a href="http://trac.edgewall.org/">http://trac.edgewall.org/</a>
 </p>
</div>



 </body></html>